<template>
	<view class="PhotoAlbum" style="overflow: hidden;">
		<!-- <view class="search">
			<uni-search-bar @confirm="search" v-model="searchValue">
			</uni-search-bar>
		</view> -->
		<view>
			<uni-list>
				<uni-list-item title="任务名称" showArrow clickable @click="selectRW" :right-text="TaskName">
					<template v-slot:footer>
						<view class="taskName">
							{{TaskName}}
						</view>
					</template>
				</uni-list-item>
			</uni-list>
		</view>
		<view>
			<u-tabs :list="list1" @click="tabClick" :current="tabsvalue"></u-tabs>
			<view v-for="tapsItem,tapsIndex in list1" :key="tapsIndex">
				<view class="photos" v-if="tabsvalue===tapsIndex">
					<!-- <uni-section title="楼层" type="line" style="width: 100%;"> -->
					<uni-grid :column="3" :showBorder="false">
						<uni-grid-item v-for="(item,index) in data" :key="index" class="photosItem">
							<image v-if="item.Mtype == 'image'" :src="item.Murl" style="width: 100%;height: 100%;"
								@click="onClickItem(index)"></image>
							<view class="videoBox" v-if="item.Mtype=='video'" @click="onClickItem(index)">
								<uni-icons size="40" color="#999" type="videocam-filled"></uni-icons>
							</view>
						</uni-grid-item>
					</uni-grid>
				</view>
			</view>
		</view>
		<ImageView ref="ImageView" :parentObj="{ ...this }"></ImageView>
		<u-picker :show="show" :columns="columns" title="选择项目" closeOnClickOverlay @close="show = false"
			@cancel="show = false" @confirm="confirm"></u-picker>
		<listitemRW ref="listitemRW" :showAdd="false" :xmId="ProjectId" :xmName="ProjectName" @itemClick="RWSelect">
		</listitemRW>
	</view>
</template>

<script>
	import ImageView from '@/components/ImageViewCopyPhoto.vue'
	import listitemRW from '@/components/listitem/listitemRW.vue'
	export default {
		components: {
			ImageView, // 图片查看
			listitemRW,
		},
		props: {
			pName: {
				require: false
			},
			pid: {
				require: true,
				type: String
			}
		},
		data() {
			return {
				isPhotoAlbum: "照片",
				// 用来判断imageViewcoyp工具栏是佛显示  显示哪些
				isUpload: true,
				isEdit: false,
				isSubmit: false,
				ProjectId: '', // 项目
				ProjectName: '',
				TaskId: '',
				TaskName: '',
				searchValue: '',
				columns: [
					['项目1', '项目2', '项目3']
				],
				show: false,
				data: [],
				tabsvalue: 0,
				list1: [{
						name: '全部图片/视频'
					},
					{
						name: '我提交的'
					},
				],
				entity: {
					xmName: "",
					xmId: "",
					rwName: "",
					rwId: "",
				},
				current: 0,
				pagination: {
					PageIndex: 1,
					PageRows: 30,
					SortField: "CreateTime",
					SortType: "desc",
				},
				total: 0,
				queryParam: {
					"Condition": "",
					"Keyword": "",
					"ProjectId": "",
					"UserId": "",
					"ControlKey": ""
				},
			}
		},
		mounted() {
			this.queryParam.ProjectId = this.pid
			this.ProjectId = this.pid
			this.ProjectName = this.pName
			// this.ProjectName = this.
			this.getDataList()
		},
		methods: {
			// 选择任务
			selectRW() {
				if (!this.ProjectId) return uni.showToast({
					icon: 'none',
					title: '请选择项目'
				})
				this.$refs.listitemRW.open()
			},
			RWSelect(row) {
				this.TaskId = row.Id
				this.TaskName = row.Name
				this.getDataList()
				console.log(row)
			},
			confirm(a) {
				console.log(a)
			},
			onClickItem(index) {
				console.log('获取是否显示工具栏', this.data, index)
				this.$refs.ImageView.open(this.data, index, false)
			},
			tabClick(a) {
				this.data = []
				this.pagination.PageIndex = 1
				this.total = 0
				if (a.index == 0) {
					this.queryParam = {
						"ProjectId": this.pid,
						"UserId": "",
						"ControlKey": ""
					}
				} else if (a.index == 1) {
					this.queryParam = {
						"ProjectId": this.pid,
						"UserId": "1",
						"ControlKey": ""
					}
				} else if (a.index == 2) {
					this.queryParam = {
						"ProjectId": this.pid,
						"UserId": "",
						"ControlKey": "楼层"
					}
				} else if (a.index == 3) {
					this.queryParam = {
						"ProjectId": this.pid,
						"UserId": "",
						"ControlKey": "区域"
					}
				} else if (a.index == 4) {
					this.queryParam = {
						"ProjectId": this.pid,
						"UserId": "",
						"ControlKey": "专业"
					}
				}
				this.tabsvalue = a.index
				this.getDataList()
				console.log(a)
			},
			// 拍照
			takePic() {
				uni.chooseImage({
					count: 1,
					success: (result) => {
						console.log(result);
						uni.navigateTo({
							url: '/pages/TakePict/TakePict?url=' + result.tempFilePaths
						})
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			// 返回项目列表页
			back() {
				uni.redirectTo({
					url: '/pages/List/ProjectList'
				})
			},
			// 去搜索
			search(res) {
				uni.showToast({
					title: '搜索：' + res.value,
					icon: 'none'
				})
			},

			concatList() {
				console.log(this.data.length, this.total);
				if (this.data.length >= this.total) return
				uni.showLoading()
				this.pagination.PageIndex++
				this.$http('Base_ProjectWork/Base_Project/GetProjectImgList', {
					...this.pagination,
					Search: {
						...this.queryParam,
						TaskId: this.TaskId,
					}
				}).then(res => {
					uni.hideLoading()
					if (res.Success) {
						this.data = this.data.concat(res.Data)
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
			},
			getDataList() {
				uni.showLoading()
				this.$http('Base_ProjectWork/Base_Project/GetProjectImgList', {
					...this.pagination,
					Search: {
						...this.queryParam,
						TaskId: this.TaskId,
					}

				}).then(res => {
					uni.hideLoading()
					if (res.Success) {
						this.data = res.Data
						this.total = res.Total
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.uni-list-item__container {
		align-items: center;
		padding: 5px;
		padding-left: 15px;
		height: 46px;
	}

	.PhotoAlbum {
		width: 100%;
		height: 100%;
		background-color: #ffffff;
		padding-bottom: 60px;
		box-sizing: border-box;
		overflow-y: scroll;
	}

	.active {
		color: #000;
	}

	.search {}

	.taps {
		display: flex;
		font-weight: 700;
		color: #999;
		padding: 0 20rpx;
		font-size: 32rpx;

		.tapItem {
			margin-right: 20rpx;
			position: relative;

			b {
				position: absolute;
				height: 10rpx;
				width: 30rpx;
				border-radius: 10rpx;
				background-color: #3872fe;
				bottom: -16rpx;
				left: 50rpx;
			}
		}
	}

	.photos {
		margin-top: 10rpx;
		// display: flex;
		// overflow-x: auto;

		.photosItem {
			// margin: 20rpx;
			// flex-shrink: 0;
			position: relative;
			padding: 5rpx;
			box-sizing: border-box;

			.videoBox {
				width: 100%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				border: 1px solid #ccc;
			}

			.top {
				width: 300rpx;
				height: 300rpx;
				border-radius: 20rpx;
				overflow: hidden;
			}

			.size {
				width: 200rpx;
				height: 200rpx;
			}

			.bottom {

				span {
					display: block;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.title {
					margin-top: 10rpx;
					font-size: 32rpx;
					font-weight: 700;
				}

				.number {
					font-size: 28rpx;
					color: #999;
				}
			}
		}
	}

	.list {
		width: calc(100% - 40rpx);
		margin: 0 auto;
		margin-top: 10rpx;
		background-color: #fff;
		border-radius: 20rpx;
		box-shadow: 0 1px 5px #ccc;

		.listItem {
			display: flex;
			line-height: 2;
			font-size: 32rpx;
			padding: 10rpx 30rpx;
			font-weight: bold;
			justify-content: space-between;

			view {
				margin: 0 10rpx;
			}
		}
	}

	.margin {
		margin: 0 2%;
	}

	.taskName {
		padding: 0 15rpx;
		font-size: 36rpx;
		color: #336dba;
		font-weight: 600;
		line-height: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>